<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <link rel="stylesheet" href="css/eui.css">
    <script src="js/vue.js"></script>
    <script src="js/axios.min.js"></script>
    <script src="js/index.js"></script>
    <style>
        body{
            margin: 0;
            background-image: url("imgs/bg1.jpg");
            background-size: cover;
        }
        #app{
            text-align: center;
        }
        h1{
            font-size: 72px;
            color: rgb(0,150,215);
            margin-bottom: 0;
        }
        img{
            width: 100px;
        }
        h2{
            font-size: 32px;
            color: #0095d7;
            margin:0;
        }

    </style>

</head>
<body>
<div id="app">
    <h1>欢迎来到酷鲨鱼商城</h1>
    <img src="imgs/shark.png">
    <h2>CoolSharkMall</h2>
    <el-card style="width: 600px;height: 300px;margin: 0 auto; background-color: rgba(255,255,255,0.3)">
        <el-form style="width: 400px;margin: 30px auto;" label-width=60px>
            <el-form-item label="用户名">
                <el-input type="text" v-model="user.username"
                placeholder="请输入用户名"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" v-model="user.password"
                          placeholder="请输入密码"></el-input>
                <el-dropdown v-model="user.password" style="margin: 20px 30px">
                    <el-button type="primary">
                        请选择身份类型<i class="el-icon-arrow-down el-icon--right"></i>
                    </el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>用户</el-dropdown-item>
                        <el-dropdown-item>管理员</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <br>
                <el-button type="primary" @click="login" style="margin-right: 50px" >登录</el-button>
                <template >
                <!-- `checked` 为 true 或 false -->
                <el-checkbox v-model="user.rem" text-color="#333740" fill="#333740">记住密码</el-checkbox>
                </template>
            </el-form-item>
        </el-form>
    </el-card>
</div>
<script>
    let v = new Vue({
        el: "#app",
        data() {
            return {
                user:{
                    password:"",
                    username:"",
                    rem:""
                }
            }
        },
        methods: {
            login(){
                axios.post("http://localhost:8080/login",v.user)
                .then(function (res) {
                    if (res.data==1){
                        if(v.user.powertype=1) {
                            location.href = "http://localhost:8080/index.html"
                        }
                        location.href="http://localhost:8080/admin.html"
                    }else{
                        alert("账号或密码错误!")
                    }
                })
            }
        }
    })
    let cookieStr = document.cookie;
    let cookieArr = cookieStr.split(";");
    for (let cookie of cookieArr) {
        let arr = cookie.split("=");
        let name = arr[0].trim();
        let value = arr[1];
        if (name == "username") {
            v.user.username = value;
        } else if (name = "password") {
            v.user.password = value;
        }
    }
</script>
</body>
</html>